package com.atguigu.dga.governance.assess.calc;

import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.governance.assess.Assessor;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import com.atguigu.dga.meta.constant.CodeConst;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component("TASK_FAILED")
public class TaskFailedAssessor extends Assessor {


    @Override
    public void checkProblem(GovernanceAssessDetail governanceAssessDetail, AssessParam assessParam) throws Exception {


        List<TDsTaskInstance> dsTaskInstanceList = assessParam.getTDsTaskInstanceList();
        if(dsTaskInstanceList==null){
            return;
        }

        boolean isFailedState=false;
        for (TDsTaskInstance tDsTaskInstance : dsTaskInstanceList) {
            if ( tDsTaskInstance.getState().intValue()==CodeConst.TASK_STATE_FAILED){
                isFailedState=true;
                break;
            }
        }
        if(isFailedState){
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("任务存在报错");
        }




    }
}
